*** College performance and contributions/withdrawals to/from the pool.  Figures G1 and G2.

global graphs "graphs/"
clear

use "${data}cleaned_data_y3.dta"

do "${blocks}construct_new_variables"

egen mean_perc_y3 = mean(Percentage_y3), by(Course)
egen sd_perc_y3   = sd(Percentage_y3), by(Course)
gen std_perc_y3   = (Percentage_y3 - mean_perc_y3) / sd_perc_y3

gen admitted_directly=1 if pool_status=="Admitted directly"
replace admitted_directly=0  if pool_status~="Admitted directly"

gen m_pooled_another_col=1 if pool_status=="Pooled another college" & Gender=="Male"
replace m_pooled_another_col=0 if pool_status~="Pooled another college" | Gender~="Male"

gen m_pooled_same_col=1 if pool_status=="Pooled same college" & Gender=="Male"
replace m_pooled_same_col=0 if pool_status~="Pooled same college" | Gender~="Male"

save "${temp}aux.dta", replace

****** College of Application

collapse (count) ApplyID (mean) admitted_directly (mean)  m_pooled_* std_perc_y1 std_perc_y3, by(FirstCollege)

format admitted_directly m_pooled_* %9.2f

foreach x of varlist admitted_directly m_pooled_* {
	gen num_`x'=ApplyID*`x'
	label var `x' "Number of `x'"
}

rename ApplyID total

save "{temp}aux2.dta", replace

****** OfferCollege 

clear 

use "${temp}aux.dta"

collapse (count) ApplyID (mean) admitted_directly (mean)  m_pooled_*, by(OfferCollege_str)

format admitted_directly m_pooled_* %9.2f

foreach x of varlist admitted_directly m_pooled_* {
	gen num_`x'=ApplyID*`x'
	label var `x' "Number of `x'"
}

rename ApplyID total

rename num_m_pooled_a m_num_taken_from_pool

rename m_pooled_a m_taken_from_pool

rename OfferCollege FirstCollege

keep FirstCollege *taken_from_pool

merge 1:1 FirstCollege using "${temp}aux2.dta"

rename FirstCollege College
rename m_pooled_another_col m_pooled_accepted_at_another
rename num_m_pooled_another_col m_num_pooled_accepted_at_another

drop _merge
drop if College=="Open Offers"

order College total num_adm m_num_taken m_num_pooled_a

scatter std_perc_y1 m_taken_from_pool, xti("Males taken from pool, % of college intake") yti("Year 1 results, standardized") graphregion(fc(white)  ) 
gr save "${graphs}m_takers_y1.gph", replace

scatter std_perc_y3 m_taken_from_pool, xti("Males taken from pool, % of college intake") yti("Year 3 results, standardized") graphregion(fc(white))
gr save "${graphs}m_takers_y3.gph", replace

graph combine "${graphs}m_takers_y1.gph" "${graphs}m_takers_y3.gph", r(1)  graphregion(fc(white) margin(t=15 b=15)) altshrink
graph export "${graphs}m_takers.pdf", replace

scatter std_perc_y1 m_pooled_accepted_at_another, xti("Males put in the pool, % of college intake") yti("Year 1 results, standardized") graphregion(fc(white))
graph save "${graphs}m_donors_y1.gph", replace

scatter std_perc_y3 m_pooled_accepted_at_another, xti("Males put in the pool, % of college intake") yti("Year 3 results, standardized") graphregion(fc(white))
graph save "${graphs}m_donors_y3.gph", replace

graph combine "${graphs}m_donors_y1.gph" "${graphs}m_donors_y3.gph", r(1) graphregion(margin(t=15 b=15) fc(white)) altshrink
graph export "${graphs}m_donors.pdf", replace
